﻿

$("#ceshi").click(function() {
	alert("1312414");

	$.post("testConnection", function(data, state) {
		if (data == 1)
			alert("数据库测试连接成功！");
		else
			alert("连接失败或数据库无表！");
	});
	console.log("4");
});

function ceshi() {
	// alert("测试");
	$("#loading").show();
	var datasent = $("#loginForm").serialize();
	params = JSON.stringify(datasent);
	$.post("testConnection", datasent, function(data, status) {
		 $("#loading").hide()
		if (status == "success") {
			if(data==1)
				alert("数据库测试连接成功！");
			else
				alert("连接失败或数据库无表！");
		} else
			alert("连接失败或数据库无表！");
	});

	/*
	 * console.log("5"); $.ajax({ url :"testConnection", type : "POST", //
	 * datatype:"json", // contentType: "application/json; charset=utf-8", data :
	 * datasent, success : function(data, stats) { if (stats == "success") {
	 * alert("数据库测试连接成功！"); } }, error : function(data) { alert("连接失败或数据库无表！"); }
	 * });
	 */

}
function lianjie() {
//	 var datasent1 ={};
//	 datasent1.datasent = ;
//	 console.log(datasent1);
	$("#loading").show();
	  var database=$('#ds_database').val();
	var datasent = $("#loginForm").serialize();
	
	var params = JSON.stringify(datasent);
	
  
	$.post("getConnection", datasent, function(data, status) {
		 $("#loading").hide()
		if (status == "success") {
			if(data==1)
				{alert("数据抽取成功！");
			 $(".ystep1").nextStep();
	    	 $("#one").hide();
	    	 $("#box1").show();
//	    	 var datasent1 ="datasent=" +  $('#bumen').html();
//			 console.log(datasent1);
//	    	 $.post("state1", datasent1, function(data, status) {
//	    		 console.log("update state1")
//	    	 });
	    //	 console.log(database);
	    	 if(database=="oracle")
	    	 var loc="jdbc:oracle:thin:@"+$('#ds_url').val();
	    	 else if(database=="sqlserver")loc="jdbc:jtds:sqlserver://"+$('#ds_url').val();
	    	var owner=$('#ds_owner').val();
	    	$("#dsname").val(owner);
         	$("#liburl").val(loc);
         	$("#buildUni").val($('#bumen').html());
//         	$("#startTime").val(null);
	       $("#startTime").val('01/01/2000');
	    	 var datas={'owner':$('#ds_owner').val(),'location':loc,'bumen':$('#bumen').html()}  ; 
			
					updatetemp();
					$('#ownerstring').html(owner.toUpperCase());
					$('#locationstring').html(loc);
					console.log($('#ownerstring').html());
					console.log($('#locationstring').html());
					console.log("updateusers all include state")
				
			 
				
//					var location="jdbc:oracle:thin:@"+$('#ds_url').val();
				
				}
			else
				alert("数据抽取失败！");
			
		} else
			alert("数据抽取失败！");
		
	
	});
	
		
	
	

}

function updatelib_lzd() {
	
	var datasent = $("#addlib").serialize();
    var ss=0;
    if($("#dsname").val()==""||$("#startTime").val()==""||$("#buildUni").val()=="") ss=1;
    else ss=2;
   
//	document.getElementById("addlib").reset(); 
	params = JSON.stringify(datasent);
	if(ss==1){alert("录入项不全！");}
	else{
	$.post("updatelib_lzd",datasent, function(data, status) {
		
		if (status == "success") {
			if(data==1)
				{alert("写入成功！");
			//	document.getElementById("addlib").reset(); 
				}
			else if(data==2)
				alert("写入失败！");
			else 
				alert("录入项不全！");
				
		} else
			alert("写入失败！");
	});
	}
	
	
	//showdiv();

	
}

function updatetemp() {
	
	var datasent = $("#addlib").serialize();
    var ss=0;
    if($("#dsname").val()==""||$("#startTime").val()==""||$("#buildUni").val()=="") ss=1;
    else ss=2;
    console.log($("#buildUni").val());
	
	params = JSON.stringify(datasent);
	if(ss==1){alert("录入项不全！");}
	else{
	$.post("updatelib_lzd",datasent, function(data, status) {
		
		if (status == "success") {
			if(data==1)
				{alert("写入成功！");
//				document.getElementById("addlib").reset(); 
				}
			else if(data==2)
				alert("写入失败！");
			else 
				alert("录入项不全！");
				
		} else
			alert("写入失败！");
		
		
	});
	}
	
	
	//showdiv();

	
}


function upcla_lzd(){

	
	var datasent = $("#addcla").serialize();
    var ss=0;
    
    if($("#bm").val()=="") ss=1;
    else ss=2;
	
	params = JSON.stringify(datasent);
	if(ss==1) {alert("录入项不全！");}
	else
		{
	$.post("updateclass_lzd",datasent, function(data, status) {
		
		if (status == "success") {
			if(data==1)
				{alert("写入成功！");
				document.getElementById("addcla").reset(); 
				}
			else if(data==2)
				alert("写入失败！");
			else 
				alert("录入项不全！");
				
		} else
			alert("写入失败！");
	});
	
		}
	//showdiv();

	
}

	




function updateobj_lzd(){
	
	var datasent = $("#addobj_lzd").serialize();
	
	params = JSON.stringify(datasent);
	$.post("updateobj_lzd", datasent, function(data, status) {
		
		if (status == "success") {
			if(data==1)
				{alert("写入成功！");
				document.getElementById("addobj_lzd").reset(); 
				}
			else if(data==2)
				alert("写入失败！");
			else 
				alert("录入项不全！");
				
		} else
			alert("写入失败！");
	});
	
	
	//showdiv();
}

function upload_lzd(){
	
//	var datasent = $("#addobj_lzd").serialize();
//	
//	params = JSON.stringify(datasent);
//	$.post("upload_lzd",
			 $.ajax({
		            type: "POST",
		            url: "upload_lzd",
		            data : "",
		            success: function(msg) {
		            }
		        });
		        return false;

	//		function(data, status) {
		
//		if (status == "success") {
//			if(data==1)
//				{alert("写入成功！");
//				document.getElementById("addobj_lzd").reset(); 
//				}
//			else if(data==2)
//				alert("写入失败！");
//			else 
//				alert("录入项不全！");
//				
//		} else
//			alert("写入失败！");
//	}
//	);
//	return false;
	
	//showdiv();
}
$.fn.serializeObject = function() {
	var o = {};
	var a = this.serializeArray();
	$.each(a, function() {
		if (o[this.name]) {
			if (!o[this.name].push) {
				o[this.name] = [ o[this.name] ];
			}
			o[this.name].push(this.value || '');
		} else {
			o[this.name] = this.value || '';
		}
	});
	return o;
};

$.fn.serializeObj = function() {
	 var o = {};
	 var a = this.serializeArray();
	 $.each(a, function() {
	  if (o[this.name]) {
	   if (!o[this.name].push) {
	    o[this.name] = [ o[this.name] ];
	   }
	   o[this.name].push(this.value || '');
	  } else {
	   o[this.name] = this.value || '';
	  }
	 });
	 return o;
	};
	
	
	
$(function(){
//	alert("111");
});	


function mdname(){
	
	var datasent = $("#addname").serialize();
	
	params = JSON.stringify(datasent);
	if(document.getElementById("mdname").value=="" ||document.getElementById("owner").value==""||document.getElementById("buildunit").value==""
		||document.getElementById("firstlev").value==""||document.getElementById("secondlev").value==""||document.getElementById("thirdlev").value==""){alert("录入项不全！");}
	else{
	$.post("addname", datasent, function(data, status) {
		
		if (status == "success") {
			if(data==1)
				{alert("写入成功！");
//				document.getElementById("addname").reset(); 
				}
			else if(data==2)
				alert("写入失败！");
			else 
				alert("写入失败！");
				
		} else
			alert("写入失败！");
	});
	}
}


function updatename(){
var datasent = $("#addname").serialize();
	console.log(datasent);
	params = JSON.stringify(datasent);
//	document.getElementById("selectuser").style.display="block";
//	document.getElementById("showresult").style.display="block";
//	document.getElementById("mdname").style.display="none";
	if(document.getElementById("mdname").value=="" ||document.getElementById("owner").value==""||document.getElementById("buildunit").value==""
		||document.getElementById("firstlev").value==""||document.getElementById("secondlev").value==""||document.getElementById("thirdlev").value==""){alert("录入项不全！");}
	else{
	$.post("updatename", datasent, function(data, status) {
		
		if (status == "success") {
			if(data==1)
				{alert("写入成功！页面将刷新！");
	         window.location.reload()  ;
			//	document.getElementById("addname").reset(); 
				}
			else if(data==2)
				alert("写入失败！");
			else 
				alert("写入失败！");
				
		} else
			alert("写入失败！");
	});
	}
}


function xiazai1(){
	
	var datasent = $("#download_lzd").serialize();
	if($("#d_owner").val()==""){alert("录入项不全！");}
	else{
	params = JSON.stringify(datasent);
//	$.post("xiazai1", datasent)
	var url="/slt/xiazai1?d_owner="+$("#d_owner").val();
	window.open(url); }
//	hidediv2all();
}
function xiazai2(){
	
	var datasent = $("#download_lzd").serialize();
	if($("#d_owner").val()==""){alert("录入项不全！");}
	else{
	params = JSON.stringify(datasent);
//	$.post("xiazai2", datasent
//	);
	var url="/slt/xiazai2?d_owner="+$("#d_owner").val();
	window.open(url);}
}
function xiazai3(){
	
	var datasent = $("#download_lzd").serialize();
	if($("#d_owner").val()==""){alert("录入项不全！");}
	else{
	params = JSON.stringify(datasent);
	
//	$.post("xiazai3", datasent
//	);
	var url="/slt/xiazai3?d_owner="+$("#d_owner").val();
	window.open(url);}
}

function login(username){
	//console.log(username);
	var datasent = null;
	if(username == null ||username==""){
		$("#welcome").show();
		$("#showresult").hide();
		alert("请从门户登录以进行元数据录入！");
		return;
//		datasent = $("#users").serialize();
//		if(datasent == null || datasent == ""){
//			$("#welcome").show();
//			$("#showresult").hide();
//			alert("请从门户登录以进行元数据录入！");
//			return;
//		}
		
	}else{
		
		datasent = "username="+username;
	}
	
	params = JSON.stringify({username:username});
	var bumen = $('#username').val();
	$('#bumen').html(username);
//	$.post("xiazai3", datasent
//	);
//	console.log("asaa = "+datasent.split("=")[1]);
	
$.post("login", datasent, function(data, status) {
	$("#next1").show();
	data = $.parseJSON(data);
	meta=data['meta'];
	data=data['lib'];
	var table1 = $('#shows1');
	var table = $('#shows');
	table.html('');
	table1.html('');
	table1.append('<tr align="center"><td colspan=10>'+'已注册的元数据'+'</td></tr>');
	table1.append('<tr><td>'+'序号'+'</td><td>'+'部门'+'</td><td>'+'元数据名称'+'</td><td>'+'数据库url'+'</td><td>'+'数据库创建用户'+'</td><td>'+'一级分类'+'</td><td>'+'二级分类'+'</td><td>'+'三级分类'+'</td><td colspan=2>'+'操作'+'</td></tr>');
	for(var i=0;i<meta.length;i++){
		var d = meta[i];
		var ii=i+1;
		table1.append('<tr><td>'+ii+'</td><td>'+d['buildUnit']+'</td><td>'+d.mdName+'</td><td>'+d['location']+'</td><td>'+d['owner']+'</td><td>'+d['firstlev']+'</td><td>'+d['secondlev']+'</td><td>'+d['thirdlev']+'</td><td>'+'<button type="button" id="meta'+i+'"  class="btn btn-primary btn-xs" onclick="editmeta(id);">编辑</button><td>'+'<button type="button" id="delete'+i+'"  class="btn btn-primary btn-xs" onclick="deletemeta(id);">删除</button></tr>');
	//	console.log(table.html());
	}
	table.append('<tr align="center"><td colspan=5>'+'已注册的数据库'+'</td></tr>');
	table.append('<tr><td>'+'序号'+'</td><td>'+'部门'+'</td><td>'+'数据库url'+'</td><td>'+'数据库创建用户'+'</td><td>'+'操作'+'</tr>');
	for(var i=0;i<data.length;i++){
		var d = data[i];
		var ii=i+1;
		table.append('<tr><td>'+ii+'</td><td>'+d['buildUnit']+'</td><td>'+d['location']+'</td><td>'+d['dsName']+'</td><td>'+'<button type="button" id="tr'+i+'"  class="btn btn-primary btn-xs" onclick="continueopt(id);">编辑</button></tr>');
	//	console.log(table.html());
	}
	
	
	
});

//var url="/slt/pages/"+data;
//window.open(url);
	
}

function editmeta(id){
	next1();
	$('#md_zhuce').hide();
	$('#md_next').hide();
	$('#md_update').show();
	$('#md_back').show();
	$('#editowner').hide();
	$('#editlocation').hide();
	$('#editdatabase').hide();
	
//	document.getElementById("selectuser").style.display="block";
//	document.getElementById("showresult").style.display="block";
//	document.getElementById("mdname").style.display="none";
	var tab=document.getElementById("shows1");
	var rows=tab.rows;
	var id=id.substring(4);
	var aaa=parseInt(id)+2;
	var locstring=tab.rows[aaa].cells[3].innerText; 
	var ownstring=tab.rows[aaa].cells[4].innerText;	
	var datasent={'owner':ownstring,'location':locstring,'bumen':$('#bumen').html()}  ; 
	$.post("metafeedback",datasent,function(data,status){
		 data = $.parseJSON(data);
		
		$('#mdName').val(data.mdName);
		$('#buildunit').val(data.buildUnit);
		$('#staff').val(data.staff);
//		$('#firstlev').val(data.firstlev);
	
//		document.getElementById("firstlev").value=data.firstlev;
	
//		$('#secondlev').val(data.secondlev);
		
//		document.getElementById("secondlev").value=data.secondlev;
	
//		$('#thirdlev').val(data.thirdlev)
//		document.getElementById("province").value=data.thirdlev;
		$('#owner').val(data.owner);
		$('#location').val(data.location);
	});
}
function deletemeta(id){
	var tab=document.getElementById("shows1");
	var rows=tab.rows;
	var id=id.substring(6);
	var aaa=parseInt(id)+2;
	var locstring=tab.rows[aaa].cells[3].innerText; 
	var ownstring=tab.rows[aaa].cells[4].innerText;	
	var datasent={'owner':ownstring,'location':locstring,'bumen':$('#bumen').html()}  ; 
	if(confirm("即将删除所有与此关联的数据，确认删除？"))
	$.post("deletemeta",datasent,function(data,status){
		if (status == "success") {
			if(data==1)
				{alert("删除成功！");
				login();
	      //   window.location = "pages/data-entrying.jsp"  ;
			//	document.getElementById("addname").reset(); 
				}
			else if(data==2)
				alert("删除失败！");
			else 
				alert("删除失败！");
				
		} else
			alert("删除失败！");
			
	});
}
function continueopt(id){
	var tab=document.getElementById("shows");
	var rows=tab.rows;
	var id=id.substring(2);
	var aaa=parseInt(id)+2;
	var locstring=tab.rows[aaa].cells[2].innerText; 
	var ownstring=tab.rows[aaa].cells[3].innerText;
	
		
		
      	$('#ownerstring').html(ownstring);
     	$('#locationstring').html(locstring);
     	document.getElementById("selectuser").style.display="none";
		document.getElementById("showresult").style.display="none";
		        $("#mdname").hide();
		         $("#box1").show();
		           var datas={'owner':$('#ownerstring').html(),'location':$('#locationstring').html(),'bumen':$('#bumen').html()}  ; 
		         $.post("updateusersAndfeedback", datas, function(data, status) {
		        	 data = eval('('+data+')');//将字符串作为js代码执行
		        	 var sdate = new Date(data.startTime); 
		         	var datestr =bu0(sdate.getMonth()+1)+'/'+bu0(sdate.getDate())+'/'+sdate.getFullYear();
		         	$("#dsname").val(data.dsName);
		         	$("#liburl").val(data.location);
		         	$("#buildUni").val(data.buildUnit);	
		         	$("#staf").val(data.staff);
		         	$("#databasestand").val(data.standname);
		         	$("#mangUnit").val(data.mangUnit);
		         	$("#mangStaff").val(data.mangStaff);
		         	$("#startTime").val(datestr);
		         	$("#keywords").val(data.keywords);
		         	$("#beizhu").val(data.beizhu);
		         	$("#attention").val(data.attention);
		         	$("#useConstr").val(data.useconstr);
		         	$("#secLev").val(data.seclevl);
		         	$("#othConstr").val(data.otherconstr);
		         	$("#exchangeEnv").val(data.exchangeEnv);
		         	$("#service").val(data.service);
		     		console.log("kaishizidongtianxie");
		     		console.log(data);
		     		
		     	});
		 }
	


function next1(){
	document.getElementById("selectuser").style.display="none";
	document.getElementById("showresult").style.display="none";
	document.getElementById("mdname").style.display="block";
        $("#md_back").show();
	
}

function backtofront(){
	document.getElementById("mdname").style.display="none";
	document.getElementById("box1").style.display="none";
	document.getElementById("showresult").style.display="block";
}
//function next1(){
//	document.getElementById("selectuser").style.display="none";
//	document.getElementById("showresult").style.display="none";
//
//	
//	var datasent ="datasent=" +  $('#bumen').html();
//	
//$.post("check", datasent, function(data, status) {
//	data = $.parseJSON(data);
////	console.log(data);
//	console.log(data);
//	var state=data['state'];
//	$('#state').html(state);
//	console.log(state);
//	
//	
//	if($('#state').html()=='0')
//		document.getElementById("mdname").style.display="block";
//	else if($('#state').html()=='1')
//             {if('owner' in data)
//            var owner=data['owner'];
//         	var location=data['location'];
//         	console.log(owner);
//         	console.log(location);
//         	$('#ownerstring').html(owner);
//         	$('#locationstring').html(location);
//		document.getElementById("selectuser").style.display="none";
//		document.getElementById("showresult").style.display="none";
//		        $("#mdname").hide();
//		         $("#box1").show();
//		           var datas={'owner':$('#ownerstring').html(),'location':$('#locationstring').html(),'bumen':$('#bumen').html()}  ; 
//		         $.post("updateusersAndfeedback", datas, function(data, status) {
//		        	 data = eval('('+data+')');//将字符串作为js代码执行
//		        	 var sdate = new Date(data.startTime); 
//		         	var datestr =bu0(sdate.getMonth()+1)+'/'+bu0(sdate.getDate())+'/'+sdate.getFullYear();
//		         	$("#dsname").val(data.dsName);
//		         	$("#buildUni").val(data.buildUnit);	
//		         	$("#staf").val(data.staff);
//		         	$("#databasestand").val(data.standname);
//		         	$("#mangUnit").val(data.mangUnit);
//		         	$("#mangStaff").val(data.mangStaff);
//		         	$("#startTime").val(datestr);
//		         	$("#keywords").val(data.keywords);
//		         	$("#beizhu").val(data.beizhu);
//		         	$("#attention").val(data.attention);
//		         	$("#useConstr").val(data.useconstr);
//		         	$("#secLev").val(data.seclevl);
//		         	$("#othConstr").val(data.otherconstr);
//		         	$("#exchangeEnv").val(data.exchangeEnv);
//		         	$("#service").val(data.service);
//		     		console.log("kaishizidongtianxie");
//		     		console.log(data);
//		     		
//		     	});
//		         
//             }
//		
//});
//
//
////var url="/slt/pages/"+data;
////window.open(url);
//	
//}
function one() {   //测试按钮，避免真导入数据、
	 
    $(".ystep1").nextStep();
	 $("#one").hide();
	 $("#box1").show();
	
//	 var datasent1 ="datasent=" +  $('#bumen').html();
//	 console.log(datasent1);
//	 $.post("state1", datasent1, function(data, status) {
//		 console.log("update state1")
//	 });
	 var datas={'owner':$('#ds_owner').val(),'location':"jdbc:oracle:thin:@"+$('#ds_url').val(),'bumen':$('#bumen').html()}  ; 
	 $.post("updateusers",datas, function(data, status) {
			
			console.log("updateusers all include state")
		});
	 
			var owner=$('#ds_owner').val();
			var location="jdbc:oracle:thin:@"+$('#ds_url').val();
			
			$('#ownerstring').html(owner.toUpperCase());
			$('#locationstring').html(location);
			console.log($('#ownerstring').html());
	}
	
function md_next() {
 	 
	 $("#mdname").hide();
	 $("#one").show();
	
	 
	}

function refreshit(){
	var datasent1 ="datasent=" +  $('#bumen').html();
	 if(confirm("确认后此条元数据默认完成，不可更改！")){
		 var datasent1={'owner':$('#ownerstring').html(),'location':$('#locationstring').html(),'bumen':$('#bumen').html()}  ; 
	 $.post("state0", datasent1, function(data, status) {
		 console.log("update state0")
		 window.location = "/slt/pages/empty-sjlr.jsp"  ;
	 });}
	 
	
}
function showtables(){
	
	$('#ownerstring').html();
	$('#locationstring').html();
   var datas={'owner':$('#ownerstring').html(),'location':$('#locationstring').html()}  ; 
	
	
	 $.post("showtables", datas, function(data, status) {
		
		if(data=='0') alert("无需补充");
		else{
			
		 data = $.parseJSON(data);
	//	console.log(data);
		DISDS = data['dsids'];
		categories = data['categories'];
//		for(var i=0;i<DISDS.length;i++){
//			console.log(DISDS[i]);
//		}
//		for(var i=0;i<categories.length;i++){
//			console.log(categories[i]);
//		}
//		console.log(categories);
		var table = $('#showalltable');
//		var data=new jStringBuffer();
//		data.append("<option value='").append("1").append("'>")
//		.append("--请选择--").append("</option>");
//		data.append("<option value='").append("1").append("'>")
//		.append("--请选择--").append("</option>");
//		data.append("<option value='").append("1").append("'>")
//		.append("--请选择--").append("</option>");
//		for(var i=0;i<category.length;i++){
//			data.append("<option value='").append(category[i].thiCode)
//			.append("'>").append(category[i].thiName).append("</option>");
//		}
//		$("#category").append(data.toString());
		
		table.html('');
		table.append('<tr><td>'+'需要完善的表'+'<td></tr>');
		table.append('<tr><td>'+'序号'+'</td><td>'+'表名'+'</td><td>'+'中文表名'+'</td><td>'+'选择第三级分类'+'</td></tr>');
		for(var i=0;i<DISDS.length;i++){
			var d = DISDS[i];
			var ii=i+1;
			var beizhu;
			if(d.beizhu==null ||d.beizhu=='') beizhu='';
			else beizhu=d.beizhu;
			table.append('<tr><td>'+ii+'</td><td>'+d.dsName+'</td><td>'+beizhu+'</td><td>'+'<select class="form-control" id="select'+d.dsCode+'" name="category"></select></td></tr>');
			$("#select"+d.dsCode).append("<option value=00>请选择</option>");
			for(var j=0;j<categories.length;j++){
			var c=categories[j];
			
			$("#select"+d.dsCode).append("<option value="+c.thiCode+">"+c.thiName+"</option>");
			$("#select"+d.dsCode).val(d.levelcode);
		//	$("#md"+d.dsCode).append("<option value='qqq'>"+d.dsCode+"</option>");
		}
//			console.log(table.html());
		}
		
		
		
		$("#upcode3").show();
		$("#updatecode3").click(function(){
			var cate=document.getElementsByName('category');
			var arr = new Array();
	         for (var k=0;k<DISDS.length;k++) {
	             var info = { "id": cate[k].id, "value": cate[k].value };
	             arr.push(info);
	         }
	        arr= JSON.stringify(arr);
	       
	        var datasent = {'arr':arr};
	        
			$.post("tablesplit",datasent, function(data, status) {
				
			//	console.info(datasent);
				if (status == "success") {
					if(data==1)
						{alert("写入成功！");
						
						}
					else if(data==2)
						alert("写入失败！");
					else 
						alert("写入失败！");
						
				} else
					alert("写入失败！");
			});
		});
		}
		
	 });
	 
}

function tempstor() {
	
	var datasent = $("#addlib").serialize();
    var ss=0;
//	document.getElementById("addlib").reset(); 
	params = JSON.stringify(datasent);
	if($("#dsname").val()==""||$("#startTime").val()==""||$("#buildUnit").val()=="") ss=1;
    else ss=2;
	if(ss==1){alert("数据库表创建用户或数据覆盖时间不能为空！");}
	else{
	$.post("updatelib_lzd",datasent, function(data, status) {
		if (status == "success") {
			if(data==1)
				{alert("保存成功！");
				}
			else if(data==2)
				alert("保存失败！");
			
		} else
			alert("保存失败！");
	});
	}
	
	
	//showdiv();
	
}
var bu0 = function(number){
    if (number<10){
        return '0'+number;
    }
    return number;
}
//$.ajax({
//	type: 'post',
//    url: 'tempstor' ,
//    //dataType: 'json', 
//    success: function(data){
//    	data = eval('('+data+')');//将字符串作为js代码执行
//    	//console.log(data);
//    	//console.log(data.staff);
//    	var sdate = new Date(data.startTime); 
//    	var datestr =bu0(sdate.getMonth()+1)+'/'+bu0(sdate.getDate())+'/'+sdate.getFullYear();
//    	$("#dsname").val(data.dsName);
//    	$("#buildUni").val(data.buildUnit);	
//    	$("#staf").val(data.staff);
//    	$("#databasestand").val(data.standname);
//    	$("#mangUnit").val(data.mangUnit);
//    	$("#mangStaff").val(data.mangStaff);
//    	$("#startTime").val(datestr);
//    	$("#keywords").val(data.keywords);
//    	$("#beizhu").val(data.beizhu);
//    	$("#attention").val(data.attention);
//    	$("#useConstr").val(data.useconstr);
//    	$("#secLev").val(data.seclevl);
//    	$("#othConstr").val(data.otherconstr);
//    	$("#exchangeEnv").val(data.exchangeEnv);
//    	$("#service").val(data.service);
//	},
//    error: function(data){
//	    console.log(data);
//	}
//});
$(document).ready(function(){

	var firstlev=$("#firstlev");
	firstlev.html('');
	$("#secondlev").html('');
	$("#thirdlev").html('');
	firstlev.append("<option value=''>请选择</option>");
	$.post("getfirstlev", function(data, status) {
		data = $.parseJSON(data);
		var firCode=null;
		var firName=null;
		var temp=null;
		temp=data[0].firCode;
		firCode=data[0].firCode;firName=data[0].firName;
		firstlev.append("<option value="+firCode+">"+firName+"</option>");
		for(var i=0;i<data.length;i++){
			firCode=data[i].firCode;firName=data[i].firName;
			if(temp!=firCode){
				temp= firCode;
				firstlev.append("<option value="+firCode+">"+firName+"</option>");
			}
		}
	
	});
})


function bao1(s){
	var firstlev=$("#firstlev");
	var select = document.getElementById("firstlev"); 
	var secondlev=$("#secondlev");
	secondlev.html('');
	$("#secondlev").html('');
	$("#thirdlev").html('');
	//alert(s);
	if(s!=''){
	//	select.options[0].selected=true;
	}
	
	secondlev.append("<option value=''>请选择</option>");
	var datasent="datasent="+s;
	$.post("getsecondlev",datasent, function(data, status) {
		data = $.parseJSON(data);
		console.log(data);
		var secCode=null;
		var secName=null;
		var temp=null;
		temp=data[0].secCode;
		secCode=data[0].secCode;secName=data[0].secName;
		secondlev.append("<option value="+secCode+">"+secName+"</option>");
		for(var i=0;i<data.length;i++){
			secCode=data[i].secCode;secName=data[i].secName;
			if(temp!=secCode){
				temp= secCode;
				secondlev.append("<option value="+secCode+">"+secName+"</option>");
			}
		}
	
	});
	

	
}
function bao2(s){

//	alert(s);
//	if(s!=''){
//		document.all.sel.options[0].selected=true;
//	}
	var thirdlev=$("#thirdlev");
	thirdlev.html('');
	thirdlev.append("<option value=''>请选择</option>");
	var firCode=$("#firstlev").val();
	var datasent={'firCode':firCode,'secCode':s};
	// datas={'owner':$('#ownerstring').html(),'location':$('#locationstring').html()}  ; 
	$.post("getthirdlev",datasent, function(data, status) {
		data = $.parseJSON(data);
		console.log(data);
		var thiCode=null;
		var thiName=null;
		var temp=null;
		temp=data[0].thiCode;
		thiCode=data[0].thiCode;thiName=data[0].thiName;
		thirdlev.append("<option value="+thiCode+">"+thiName+"</option>");
		for(var i=0;i<data.length;i++){
			thiCode=data[i].thiCode;thiName=data[i].thiName;
			if(temp!=thiCode){
				temp= thiCode;
				thirdlev.append("<option value="+thiCode+">"+thiName+"</option>");
			}
		}
		thirdlev.append("<option value=00>无法确定</option>");
	});
	

	
}
